package com.chisheng.caa.pojo.dto;

import com.alibaba.excel.annotation.ExcelProperty;
import com.chisheng.caa.convertor.StudyingTermConverter;
import com.chisheng.caa.service.CollegeService;
import com.chisheng.caa.service.CourseNatureService;
import com.chisheng.caa.validator.Contains;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.lang.Nullable;
import com.chisheng.caa.pojo.Bean;

import javax.validation.constraints.*;
import java.io.Serializable;

@Data
@ApiModel("课程信息数据传输类")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CourseDTO implements Serializable, Bean {

    private static final long serialVersionUID = 1L;

    /**
     * 有效的课程代码校验正则表达式。
     */
    public final static String COURSE_CODE_REGEX = "^([0-9]{8})$";

    @Nullable
    @ApiModelProperty("课程性质 / 课程类别")
    @Contains(beanClass = CourseNatureService.class, methodName = "getCourseNatureNameList", message = "{ImportedCurriculum.courseNature.message}")
    @ExcelProperty({"课程性质", "课程类别"})
    private String courseNature;

    @NotBlank(message = "{ImportedCurriculum.courseCode.message}")
    @ApiModelProperty("课程代码")
    @Pattern(regexp = COURSE_CODE_REGEX, message = "{ImportedCurriculum.courseCode.message}")
    @ExcelProperty("课程代码")
    private String courseCode;

    @Nullable
    @ApiModelProperty("课程名称")
    @Size(min = 1, message = "{ImportedCurriculum.courseName.message}")
    @ExcelProperty({"课程名称"})
    private String courseName;

    @Nullable
    @ApiModelProperty("理论学分")
    @DecimalMin(value = "0.0", message = "{ImportedCurriculum.credit.message}")
    @ExcelProperty({"理论学分"})
    private Double theoreticalCredit;

    @Nullable
    @ApiModelProperty("实践学分")
    @DecimalMin(value = "0.0", message = "{ImportedCurriculum.credit.message}")
    @ExcelProperty({"实践学分"})
    private Double practicalCredit;

    @Nullable
    @ApiModelProperty("理论学时")
    @Min(value = 0, message = "{ImportedCurriculum.period.message}")
    @ExcelProperty({"理论学时"})
    private Integer theoreticalPeriod;

    @Nullable
    @ApiModelProperty("实践学时")
    @Min(value = 0, message = "{ImportedCurriculum.period.message}")
    @ExcelProperty({"实践学时"})
    private Integer practicalPeriod;

    @Nullable
    @ApiModelProperty("自学学时")
    @Min(value = 0, message = "{ImportedCurriculum.period.message}")
    @ExcelProperty({"自学学时"})
    private Integer selfPeriod;

    @NotNull(message = "{{ImportedCurriculum.studyingTerm.message}}")
    @ApiModelProperty("修读学期")
    @Min(value = 0, message = "{ImportedCurriculum.studyingTerm.message}")
    @Max(value = 8, message = "{ImportedCurriculum.studyingTerm.message}")
    @ExcelProperty(value = "建议首次修读学期", converter = StudyingTermConverter.class)
    private Integer studyingTerm = 0;

    @Nullable
    @ApiModelProperty("考核方式")
    @Contains(beanName = "validExaminationTypeList", message = "{ImportedCurriculum.examinationType.message}")
    @ExcelProperty("考核方式")
    private String examinationType;

    @Nullable
    @ApiModelProperty("先修课程")
    @ExcelProperty({"先修课程"})
    private String preStudyingCourse;

    @Nullable
    @ApiModelProperty("开课学院")
    @Contains(beanClass = CollegeService.class, methodName = "getCollegeNameList", message = "{ImportedCurriculum.college.message}")
    @ExcelProperty({"开课学院"})
    private String openingCollege;

    @Nullable
    @ApiModelProperty("授课学院")
    @Contains(beanClass = CollegeService.class, methodName = "getCollegeNameList", message = "{ImportedCurriculum.college.message}")
    @ExcelProperty({"授课学院"})
    private String teachingCollege;

    @Nullable
    @ApiModelProperty("备注")
    @ExcelProperty({"备注"})
    private String attachment;

    @Override
    @JsonIgnore
    public String getKey() {
        return courseCode;
    }

}
